<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>修改作品</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="${pageContext.request.contextPath }/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <!-- jqgrid-->
    <link href="${pageContext.request.contextPath }/css/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/animate.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/style.css?v=4.1.0" rel="stylesheet">
    <script src="${pageContext.request.contextPath }/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath }/js/bootstrap.min.js?v=3.3.6"></script>
    
    <!-- 自定义js -->
    <script src="${pageContext.request.contextPath }/js/content.js?v=1.0.0"></script>
    <!-- jQuery Validation plugin javascript-->
    <script src="${pageContext.request.contextPath }/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/plugins/validate/messages_zh.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/plugins/layer/layer.min.js"></script>
    
	<style>
		input,select{
			 width:168px;
			 height:25px;
			 border:1px solid #ccc;
			 margin-left:24px;
		}
		.label-text{
			width:80px;
			text-align:right;
		}
	</style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content  animated fadeInRight">
        <div class="row">
            <div class="col-sm-6">
                <div class="social-feed-box">
                    <div class="social-footer">
						<form name = "form1" id = "update_ar"  enctype='multipart/form-data'>
<%-- 							<input type = "text" name = "targetId" id = "targetId" value = "${ea.targetId }"/><br/><br/> --%>
							<input type = "hidden" name = "id" id = "id" value = "${ea.id }"/><br/><br/>
							<label class="label-text">所属地区：</label>
								<select name = "region" id = "region"  onchange="get_select_region()">
						    		<option value="0" >全国</option>
									<c:forEach items="${regionList }" var = "e">
										<option value = "${e.code }">${e.title }</option>
									</c:forEach>
								</select>
								<select name = "regionId" id = "regionId"  onchange="get_select_county()">
						    		<option value="" >请选择</option>
										<option value = "">请选择</option>
								</select>
								<select name = "regionId2" id = "regionId2">
						    		<option value="" >请选择</option>
										<option value = "">请选择</option>
								</select>
							<label class="btn btn-primary" onclick = "updateRecommend()">保存</label>
					    </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

</body>

    
    <script type="text/javascript">
 
 	function cancel(){
 		var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        parent.layer.close(index);
 	}
      
	//修改或修改
	function updateRecommend(){	
		var regionCode = $("#regionId2").val();
		if(regionCode == '' || regionCode == null){
			regionCode = $("#region").val();
		}
		var easyArId = $("#id").val();
		$.ajax({
    		url:"${pageContext.request.contextPath }/admin/arRecommend/updateRecommend",
    		data:{easyArId:easyArId,regionCode:regionCode},
    		type:"post",
    		success:function(data){
    			if(data.code == '0'){
					layer.msg(data.message,{icon:1});
					setTimeout('cancel()',1000);
    			}else {
					layer.msg(data.message,{icon:0});
    			}
    		}
    	});
	}
	
	//获取市
	function get_select_region(){
		var code = document.getElementById('region').value.replace(",","");
		var hangyeItem = $("#regionId");
		var hangyeItem1 = $("#regionId2");
		hangyeItem.empty();
		hangyeItem1.empty();
		$.get("/admin/region/getItems/"+code, function(result){
			var option0 = $("<option>").text('选择分类').val('');
			hangyeItem.append(option0);
			for(var i=0;i<result.length;i++) {
				if(i == 0){
					var option = $("<option>").text(result[i].title).val(result[i].code).attr("selected","selected");
				}else{
					var option = $("<option>").text(result[i].title).val(result[i].code);
				}
				hangyeItem.append(option);
			}
			var countyCode = result[0].code;
			$.get("/admin/region/getItems/" + countyCode, function(result){
				var city = $("#regionId2");
				city.empty();
				for(var i=0;i<result.length;i++) {
					var option = $("<option>").text(result[i].title).val(result[i].code);
					city.append(option);
				}
			});
		});
	}
	
	
	//获取县
	function get_select_county(){
		var code = document.getElementById('regionId').value.replace(",","");
		$.get("/admin/region/getItems/" + code, function(result){
			var city = $("#regionId2");
			city.empty();
			for(var i=0;i<result.length;i++) {
				if(i == 0){
					var option = $("<option>").text(result[i].title).val(result[i].code).attr("selected","selected");
				}else{
					var option = $("<option>").text(result[i].title).val(result[i].code);
				}
				city.append(option);
			}
		});
	}
	
	</script>
</html>
